






jQuery.fn.highlight = function (text, o) {
	return this.each( function(){
		var replace = o || '<span class="highlight">$1</span>';
		jQuery(this).html( html.replace( new RegExp('('+text+'(?![\\w\\s?&.\\/;#~%"=-]*>))', "ig"), replace) );
	});
}

jQuery.fn.autolink = function () {
	return this.each( function(){
		var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
		jQuery(this).html( jQuery(this).html().replace(re, '<a href="$1" target="_blank">$1</a>') );
	});
}

jQuery.fn.mailto = function () {
	return this.each( function() {
		var re = /(([a-z0-9*._+]){1,}\@(([a-z0-9]+[-]?){1,}[a-z0-9]+\.){1,}([a-z]{2,4}|museum)(?![\w\s?&.\/;#~%"=-]*>))/g
		jQuery(this).html( jQuery(this).html().replace( re, '<a href="mailto:$1";>$1</a>' ) );
	});
}

jQuery.fn.trim = function(str) {
	return typeof(str) == 'string' ? str.replace(/^\s\s*/, '').replace(/\s\s*$/, '') : '';
}

jQuery.extend({
	getUrlVars: function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	},
	getUrlVar: function(name){
		return jQuery.getUrlVars()[name];
	}
});

var shortConsumerKey = null;
var cssPath			= null;
var livereReply		= null;
var result			= null;
var listResult		= null;
var replyResult		= null;
var countResult		= 0;

Livere = function( p_rep , p_targetDIV, p_title , p_tag , p_twitterAccount, p_s_id , p_skin_id, p_moreDefine, p_syncDomain, p_minimum_text, p_textLength ) {
	
	this.rep 			= p_rep.indexOf("http://") == 0 ? escape(p_rep.substr(7)) : escape(p_rep);
	this.moreDefine		= !p_moreDefine ? 10 : p_moreDefine;
	this.syncDomain		= p_syncDomain;
	this.skin_id		= p_skin_id;
	this.s_id			= p_s_id;
	
	this.targetDIV		= p_targetDIV;
	this.title			= jQuery.trim(p_title);
	this.titleInit		= true;
	this.tag			= p_tag;
	this.twitterAccount	= p_twitterAccount;
	this.textLength		= !p_textLength ? 250 : p_textLength;
	this.minimum_text	= !p_minimum_text ? 5 : p_minimum_text;
	this.defaultNewline	= "<br />";
	this.pageBlock		= 10;
	
	this.guestIcon		= "http://www.livere.co.kr/public/icon/guest/a.png";
	
	this.initMessage	= {};
	
	this.initMessage.secretContent	= "관리자만 볼 수 있는 비밀 글 입니다";
	this.initMessage.needLogin		= "로그인 후 이용 가능합니다";
	this.initMessage.snsid			= "로그인 후 댓글을 작성하여 주세요";	
	this.initMessage.pltfrm_txt		= "";
	this.initMessage.writeCount		= this.textLength;
	this.initMessage.deleteConfirm	= "삭제하시겠습니까?";
	this.initMessage.deleteAuthFail	= "본인 글만 삭제가능합니다";
	this.initMessage.deleteFail		= "삭제에 실패하였습니다";
	this.initMessage.title			= "로그인 후 작성 가능합니다";
	this.initMessage.replyCount_txt	= "전체댓글수 ";
	this.initMessage.replyCount_txt2= "";
	this.initMessage.textCount_txt 	= "";
	this.initMessage.linkLivere		= "라이브리에 연동하시겠습니까?";
	this.initMessage.secret_txt		= "비밀글쓰기";
	this.initMessage.reactionA		= "이미 참여하셨습니다";
	this.initMessage.reactionB		= "참여해주셔서 감사합니다";
	this.initMessage.emptyReply		= "본문없이 제목만 포스팅 하시겠습니까?";
	this.initMessage.lowFlowMessage		= "자 이상 입력해주세요";
	this.initMessage.overFlowMessage		= "자 까지만 입력 가능합니다";
	
	this.initMessage.needNameAndPassword	= "이름과 비밀번호를 입력하여 주세요";
	
	this.initMessage.fire	= function() {
		jQuery(".primarySNS > strong").removeClass().addClass("snsid").text( this.snsid );
		jQuery(".pltfrm_txt").html( this.pltfrm_txt );
		jQuery(".logout").addClass("off");
		livereReply.priObj._data = null;
		jQuery(".primaryThumbnail").addClass("off");
		jQuery("#contentText").val( this.title );
		jQuery(".accountLayer").remove();
	}
	
	// 대표 도메인
	this.priObj			= Object();
	this.priObj._data	= null;
	this.priObj.setData = function( obj ) {
	
		if(this._data == obj) {
			return;
		}
	
		if(obj.MEMBER_ISPRI) {
			this._data = obj;
			obj.USER_ICON	= obj.MEMBER_ICON;
			jQuery("#livereUserName").val( obj.MEMBER_NAME );
			jQuery(".primaryThumbnail").removeClass("off").attr("src", obj.USER_ICON);
			jQuery(".logout").removeClass("off");
			jQuery(".primarySNS > strong").removeClass().addClass( obj.name ).text( obj.MEMBER_NAME );
						
			jQuery(".sns_icons_wrapper > span").find("a").removeClass("primary").end().find("a." + obj.name).addClass("primary");
			
			jQuery("#contentText").val( livereReply.titleInit ? livereReply.title + " "  : "" );
			
			if( livereReply.guestManager ) {
				livereReply.guestManager.unset();
			}
		}
	}
	
	this.priObj.isLogged = function( withAlert ) {

		var returnFlag = livereReply.priObj._data ? true : false;
		
		if( !returnFlag && withAlert ) {
			alert( livereReply.initMessage.needLogin );
		}
		
		return returnFlag;
	}

	this.accountManager	= Object();
	
	this.accountManager.sync = Object();
	this.accountManager.sync.syncstart = function() {
		var domain = eval(livereReply.syncDomain);
		if( livereReply.forceSync || ( livereReply.accountManager.sync.need() && !domain.MEMBER_ISLOGIN ) ) {
			setTimeout( "eval(livereReply.syncDomain).syncStart()" , 1000 );
		}
	}
	
	this.accountManager.sync.syncoff = function() {
		var syncDomain = livereReply.syncDomain;
		
		var domainObject = livereReply.accountManager.getDomain( syncDomain );
		
		if( domainObject && (domainObject.tryLogin || domainObject.MEMBER_ISLOGIN || domainObject.LOGIN_HISTORY) ) {
			eval(livereReply.syncDomain).syncOff( livereReply.rep );
		}
		
	}
	
	this.accountManager.sync.need = function() {
		return (livereReply.syncDomain && !eval(livereReply.syncDomain).tryLogin && !livereReply.priObj.isLogged());
	}
	
	this.accountManager.isAbleAccount = function( member_seq ) {
		var returnFlag = false;
		
		jQuery( livereReply.accountManager.array ).each( function( idx , obj ) {
			if( obj.MEMBER_SEQ == member_seq && obj.support ) {
				returnFlag = true;
				return false;
			} 
		} );
		
		return returnFlag;
	}

	this.accountManager.isMember = function( member_seq ) {
		var returnFlag = false;
		
		jQuery( livereReply.accountManager.array ).each( function( idx , obj ) {
			if( obj.MEMBER_SEQ == member_seq ) {
				returnFlag = true;
				return false;
			} 
		} );

		return returnFlag;
	}
	
	this.accountManager.add = function( obj ) {
		if(!this.array) this.array = Array();
		this.array.push( obj );
	}

	this.accountManager.setAccount = function() {
		
		var targetDIV = jQuery(".sns_icons_wrapper");
		jQuery( this.array ).each( function( idx , obj ) {
			if( obj.support ) {
				var html = "<span id='" + obj.name + "_icon'><a href=\"javascript:livereReply.accountAction('" + obj.name + "');\" class='" + obj.name + "'></a></span>";
				obj.icon = jQuery(html);
				jQuery( targetDIV ).append( obj.icon );
			}
		} );		
	}

	this.accountManager.initArray = function() {
		jQuery( this.array ).each( function( idx, obj ) {
			obj.MEMBER_ISLOGIN = false;
		});
	}
	
	this.accountManager.getDomain	= function( domainName ) {
		jQuery( this.array ).each( function( idx, obj ) {
			if( obj.name == domainName )
				return obj;
		} );
		
		return null;
	}

	this.accountManager.mergeAccount = function( jsonArr , justClear ) {
		
		livereReply.initMessage.fire();
		this.initArray();

		if( justClear ) {
			this.drawLoginData();
			return;
		}
		
		var logged			= false;
		var target			= null;
		
		jQuery( this.array ).each( function( idx, obj ) {
			if( obj.support ) {
				
				jQuery( jsonArr ).each( function (idx2 , obj2) {
				
					var cashDomain	= obj;
					var getDomain	= obj2;
					
					if(getDomain.MEMBER_DOMAIN && cashDomain.name == getDomain.MEMBER_DOMAIN.toLowerCase()) {
						cashDomain = jQuery.extend( cashDomain , getDomain );
						
						cashDomain.MEMBER_ISPRI		= getDomain.MEMBER_ISPRI == "1" ? true : false;
						cashDomain.MEMBER_ISLOGIN	= getDomain.MEMBER_ISLOGIN == "1" ? true : false;
						cashDomain.MEMBER_ISPOST	= getDomain.MEMBER_ISPOST == "1" ? true : false;
						cashDomain.LOGIN_HISTORY	= true;
						
						livereReply.priObj.setData( getDomain.MEMBER_ISPRI == "1" ? cashDomain : livereReply.priObj._data );
						target = cashDomain.name;
						
						return false;
					}
					
					logged = true;
					
				});
			}
		});
		
		if(logged && livereReply.priObj._data == null && target) {
			livereReply.changePrimary( target , true );
		}
		
		livereReply.accountManager.sync.syncstart();
		this.drawLoginData();
	}
	
	this.accountManager.drawLoginData = function() {
		var manager = this;
		jQuery( this.array ).each( function( idx, obj ) {
			manager.loginControl( obj.name );
		});
	}

	this.accountManager.loginControl = function( domain ) {
		var target = this.getDomain( domain );
		if(target.support) {
			if(target.MEMBER_ISLOGIN && !target.MEMBER_ISPOST) {
				target.icon.addClass("NotPost");
			} else if ( target.MEMBER_ISLOGIN ) {
				target.icon.removeClass("NotPost").addClass("on");
			} else {
				target.icon.removeClass("on");
				target.icon.removeClass("NotPost");
			}
		}
	}

	this.accountManager.doLogout = function( domain ) {
		var target = this.getDomain( domain );
		target.MEMBER_ISLOGIN = false;
		this.loginControl( target );
	}

	this.accountManager.doLogin = function( domain ) {
		var target = this.getDomain( domain );
		target.MEMBER_ISLOGIN = true;
		this.loginControl( target );
	}

	this.accountManager.clickAction = function( domain ) {
		
		var target = this.getDomain( domain );
		if( target.MEMBER_ISLOGIN ) {
			jQuery(".accountLayer").remove();
			
			if(target.layer_isopen) {
				target.layer_isopen = false;
				return;
			}
			target.layer_isopen = true;
			
			var actionControlBox = "";
			actionControlBox += "<div class='accountLayer'>";
			actionControlBox += "	<a class='layerClose' href=\"javascript:livereReply.accountAction('" + target.name + "');\"></a>";
			actionControlBox += "	<dl>";			
			actionControlBox += "		<dd class='accountLayer_sns_icon'><span class='" + target.name + "'>" + target.MEMBER_NAME + "</span></dd>";
			actionControlBox += "		<dd class='accountLayer_button_wrapper'>";
			actionControlBox += "			<a class='primarySet' href=\"javascript:livereReply.changePrimary('" + target.name + "')\"></a>";
			actionControlBox += "			<a class='postingChoice' href=\"javascript:livereReply.setPostingDomain('" + target.name + "')\"></a>";
			actionControlBox += "			<a class='selfLogout' href=\"javascript:livereReply.domainLogout('" + target.name + "')\"></a>";
			actionControlBox += "		</dd>";
			actionControlBox += "	</dl>";
			actionControlBox += "</div>";
			
			target.icon.append( jQuery(actionControlBox) );
		} else {
			target.loginGate( livereReply.rep );
		}
	}

	// accountManager util
	this.accountManager.getDomain = function( domain ) {
		return typeof(domain) == "string" ? eval(domain) : domain;
	}

	this.getFormHTML = function() {
		var formHTML = "";
		formHTML += "<div id='livere_platform'>";		
		formHTML += "<div id='livereBanner'></div>"
		formHTML += "<div id='platform_wrapper'>";
		formHTML += "	<div class='livere_logo_half'></div>";
		formHTML += "	<div class='pltfrm_top login'>";
		formHTML += "		<div class='sns_icons_wrapper'>";
		formHTML += "		</div>";
		formHTML += "		<a class='logout off' href=\"javascript:livereReply.livereLogout()\"></a>";
		formHTML += "		<span class='pltfrm_txt'>" + this.initMessage.pltfrm_txt + "</span>";
		formHTML += "	</div>";
		formHTML += "	<div id='pltform_middle'>";
		formHTML += "			<span class='primarySNS'>";
		formHTML += "				<strong class='snsid'>" + this.initMessage.snsid + "</strong>";
		formHTML += "			</span>";
		formHTML += "			<span class='attachButton'>";
		formHTML += "           	<a class='attachImage' href=\"javascript:livereReply.attachAction('image')\"></a>";
		formHTML += "           	<a class='attachVideo' href=\"javascript:livereReply.attachAction('movie')\"></a>";
		formHTML += "			</span>";
		formHTML += "			<span class='writeCountWrapper'>" + this.initMessage.textCount_txt + "<strong class='writeCount'>" + this.initMessage.writeCount + "</strong></span>";
		formHTML += "			<fieldset>";
		formHTML += "				<div class='thumbnail'><img class='primaryThumbnail off' /></div>";
		formHTML += "                <div class='contentInput'>";
		formHTML += "                    <form id='livereForm' name='livereForm'>";
		formHTML += "                        <input type='hidden' name='twitterAccount' id='twitterAccount' />";
		formHTML += "                        <input type='hidden' name='w_parent' id='w_parent' />";
		formHTML += "                        <input type='hidden' name='livereUserName' id='livereUserName' />";
		formHTML += "                        <input type='hidden' name='referer' id='referer' />";
		formHTML += "                        <input type='hidden' name='tag' id='tag' />";
		formHTML += "                        <input type='hidden' name='livereTitle' id='livereTitle' />";
		formHTML += "                        <input type='hidden' name='w_image' id='w_image' />";
		formHTML += "                        <textarea name='contentText' rows='3' cols='90' id='contentText' onkeyup=\"javascript:livereReply.textboxAction(this)\"></textarea>";
		formHTML += "                    </form>";
		formHTML += "                </div>";
		formHTML += "                <div class='sendFunction'><a class='send' href=\"javascript:livereReply.fire('sendAction')\"></a></div>";
		formHTML += "            </fieldset>";
		formHTML += "	</div>";
		formHTML += "	<div id='activeCheck'></div>"
		formHTML += "	<a class='powered_by' href='http://www.livere.co.kr/' target='_blank'></a>";
		formHTML += "</div>";
		formHTML += "</div>";

		return formHTML;
	}

	
	
	this.attachFileComplete = function() {
	
		var url = livereReply.url( "GetLivereAttached" );
		jQuery.getJSON( url , function(data) {
			var jsnReply = livereReply.convertJSON( data );
			
			jQuery("#contentText").val( jQuery("#contentText").val() + " " + jsnReply.ATTACHITEM );
			jQuery("#w_image").val( jsnReply.ATTACHITEM );
			 
		} );
	}
	
	
	
	this.attachAction = function( selected ) {
		if(!livereReply.priObj.isLogged( true )) {
			return;
		}
		
		var url = livereReply.url( "ver5/livereUploadwindow.jsp?custompath=" + cssPath + "&selected=" + selected , "exportURL=" + livereReply.rep );
		
		livereReply.popup( url , 400, 170 );
		
		livereReply.popup( url );
	}
	
	
	this.sendAction = function( parent_code ) {
		
		if( !livereReply.priObj.isLogged( true ) || !livereReply.accountManager.isAbleAccount( livereReply.priObj._data.MEMBER_SEQ ) ) {
			return;
		}

		var fm = jQuery("#livereForm");
		var params = "";
		var comment = "";
		var useTitle = typeof(livereReply.title) == 'string' && livereReply.title.length > 0;
		
		if(parent_code) {
		
			var obj = document.getElementById("replyText");
			if(obj.value.length > livereReply.textLength) {
		    	alert( livereReply.textLength + livereReply.initMessage.overFlowMessage);
		    	obj.value = obj.value.substring(0, (livereReply.textLength-2));
		    	
		    	return;
		    }
		    
			jQuery("#w_parent").val( parent_code );
			comment = jQuery("#replyText").val();
		} else if( useTitle ) {
			var comment = jQuery("#contentText").val();
			comment = comment.replace( livereReply.title , '' );
		} else {
			comment = jQuery("#contentText").val();
		}
		
		if( comment.length < livereReply.minimum_text ) {
			if( useTitle && comment.length < 2)  { 
				if(!confirm(livereReply.initMessage.emptyReply)) return;
				comment = livereReply.title;
			} else {
				alert( livereReply.minimum_text + livereReply.initMessage.lowFlowMessage);
				return;
			}
		}
		
		jQuery("#contentText").val( comment );
		jQuery("#livereTitle").val( livereReply.title );
		jQuery("#referer").val( unescape( livereReply.rep ) );
		jQuery("#twitterAccount").val( livereReply.twitterAccount );
		jQuery("#tag").val( livereReply.tag );
		
		fm.children().each( function( idx , obj ) {
			var value = jQuery(obj).val();
			if(value != "") {
				params += obj.name + "=" + encodeURIComponent(jQuery(obj).val()) + "&";
			}
		});

		params = params.substr( params.length-1 ) == "&" ? params.substr( 0, params.length-1 ) : params;
		
		var url = livereReply.url( "LivereInsert" , params );
		
		jQuery.getJSON( url , function( data ) {
			var param = {};
			param['data'] = data;
			
			return livereReply.fire('attachReply' , param);
		});
	}
	
	
	this.attachReply = function( param ) {
	
		var data = param['data'];
		var jsnReply = livereReply.convertJSON( data , "FA" );
			
		if(jsnReply == null) {
			alert("도배는 나빠요~");
			return false;
		}

		if(livereReply.priObj._data)		
			jQuery.extend( jsnReply , livereReply.priObj._data);

		jsnReply.RE_CONTENT	= jsnReply.CONTENTTEXT;
		jsnReply.RE_PARENT		= !jsnReply.W_PARENT ? jsnReply.RE_CODE : jsnReply.W_PARENT;

		var d = new Date();

		var date1   = livereReply.leadingZeros(d.getFullYear(), 4) + "-" + livereReply.leadingZeros((d.getMonth()+1), 2) + "-" + livereReply.leadingZeros(d.getDate(), 2);
        var date2   = livereReply.leadingZeros(d.getHours(),2) + ":" + livereReply.leadingZeros(d.getMinutes(), 2) + ":" + livereReply.leadingZeros(d.getSeconds(), 2);

		jsnReply.RE_REGDATE1	= date1;
		jsnReply.RE_REGDATE2	= date2;
		jsnReply.RE_AGREE		= jsnReply.RE_BAD = "0";
		
		var reObject = livereReply.listManager.getReplyHTML( jsnReply );
		
		var param = {};
		param['replyObject']	= reObject;
		param['isNewReply']		= livereReply.listManager.totalCount == 0 ? false : true;
		
		livereReply.fire( "addReply" , param );
		
		//livereReply.listManager.addReply( reObject , livereReply.listManager.totalCount == 0 ? false : true );

		jQuery("#w_parent").val( "" );
		jQuery("#contentText").val( livereReply.titleInit ? livereReply.title : "" );

		if( jsnReply.RE_CODE != jsnReply.RE_PARENT ) {
			livereReply.listManager.drawReplyForm( jsnReply.RE_PARENT );
		}

		livereReply.listManager.totalCountControl( +1 );
		
		return jsnReply;
	}
	
	this.textboxAction = function( obj ) {
	
		if(!livereReply.priObj.isLogged()) {
			obj.value = this.initMessage.needLogin;
			return;
		}
		
		// active
		if(livereReply.active) {
			livereReply.active.write( obj.value );
		}
		
	    var str_len = obj.value.length;
	    jQuery(".writeCount").html( str_len + "/" + livereReply.textLength );
	    if(str_len > livereReply.textLength) {
	    	alert( livereReply.textLength + livereReply.initMessage.overFlowMessage);
	    	obj.value = obj.value.substring(0, (livereReply.textLength-2));
	    	
	    	livereReply.textboxAction(obj);
	    }
	}
	
	
		
		
	this.livereLogout = function() {
		jQuery.getScript( this.url("LiveReLogOut" ), function( data ) {
			livereReply.accountManager.mergeAccount( null , true );
			livereReply.accountManager.sync.syncoff();
			if(livereReply.guestManager) {
				livereReply.guestManager.init();
			}
		});
	}
	
	
	this.changePrimary = function( domain , isDirect ) {
		
		if(!isDirect) this.accountAction( domain );
		domain = this.accountManager.getDomain( domain );
		
		if( domain != null ) {
			var url = this.url("SetPrimarySNS" , "member_seq=" + domain.MEMBER_SEQ);
			jQuery.getScript( url, function() {
				livereReply.renewMembership();
			});
		}
		
	}

	this.domainLogout = function( domain ) {
		this.accountAction( domain );
		domain = this.accountManager.getDomain( domain );
		var param = "member_seq=" + domain.MEMBER_SEQ + "&logoutDomain=" + domain.MEMBER_DOMAIN;
		jQuery.getScript( this.url("DomainLogOut" , param ), function() {
			livereReply.renewMembership();
		});
	}
	
	this.setPostingDomain = function( domain ) {
		this.accountAction( domain );
		domain = this.accountManager.getDomain( domain );
		var isPost = domain.MEMBER_ISPOST != 0 ? 0 : 1;
		var param = "member_seq=" + domain.MEMBER_SEQ + "&member_ispost=" + isPost;
		jQuery.getScript( this.url("setPostingDomain" , param ), function() {
			livereReply.renewMembership();
		});
	}
		
	this.renewMembership = function() {
		
		var param	= "apitype=cookielogin";
		var url = livereReply.url("LivereAPI" , param);
		jQuery.getJSON( url , function(data) {
			
			var result = livereReply.convertJSON( data );
			livereReply.accountManager.mergeAccount( result );
		});
		
	}

	this.accountAction = function( snsName ) {
		this.accountManager.clickAction( snsName );
	}

	// livereUtils
	this.replaceAll = function( source , stringToFind , stringToReplace ) {
		var temp = source;
		var index = temp.indexOf(stringToFind);
		while(index != -1){
		    temp = temp.replace(stringToFind,stringToReplace);
		    index = temp.indexOf(stringToFind);
		}
		return temp;
	}
	
	this.autoLink = function( obj ) {
		var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
		return obj.replace(re, '<a href="$1" target="_blank">$1</a>');
	}

	this.popup = function(url, width, height) {
		var left = (screen.width - width) / 2 ; 
		var top = (screen.height - height) / 2;                   
		var popupProperties = "width="+ width + ",height=" + height + ",left="+ left +",top="+ top +",scrollbars=0";
		window.open(url, "attach", popupProperties);
	}
	this.leadingZeros = function(n, digits) {
        var zero = '';
        n = n.toString();

        if (n.length < digits) {
            for (i = 0; i < digits - n.length; i++)
            zero += '0';
        }
        return zero + n;
    }
    
	this.url = function( urlAddon , param , prefix) {
		if(param == true) {
			return urlAddon + prefix + "&dummy=" + Math.random() + "&domain=" + document.domain + "&re_refer=" + livereReply.rep;
		}
		urlAddon = livereReply.urlSet.getUrl( urlAddon );
		var url = "http://www.livere.co.kr/" + urlAddon + "?dummy=" + Math.random() + "&livereCallback=?&domain=" + document.domain + "&re_refer=" + livereReply.rep;
		return param ? url + "&" + param : url
	}

	this.setActiveAccount = function( object ) {
		this.accountManager.add( object );
	}
	
	this.reInit = function( targetLayer ) {
		jQuery("#" + targetLayer).append( jQuery("#livere_platform") );
		jQuery("#contentText").val( livereReply.titleInit ? livereReply.title + " "  : "" );
		
		var param	= "apitype=count";
		var url = livereReply.url("LivereAPI" , param);
		
		jQuery.getJSON( url , function(data) {
			var data = livereReply.convertJSON( data );
			livereReply.listManager.totalCount = 0;
			livereReply.listManager.totalCountControl( parseInt(data.COUNT) );
			
			var params = {};
			params['sort']		= 'new';
			params['page']		= 1;
			params['needClear']	= true;
			
			livereReply.fire('getArticle' , params);
		} );
	}

	this.articleAction = function( re_code , type ) {
		var obj = livereReply.listManager.getObject( re_code ).wrapper;
		
		var param	= "apitype=reaction&re_code=" + re_code + "&type=" + type;
		var url = livereReply.url("LivereAPI" , param);
		
		jQuery.getJSON( url , function(data) {
			var result = livereReply.convertJSON( data );
			switch ( result.RESULT ) {
				case "-2" :
					alert( livereReply.initMessage.reactionA );
					break;
				default :
					var target = type == 'good' ? obj.find( ".recommend_count" ) : obj.find( ".sympathy_count" );
					
					var no = parseInt( target.html() );
					target.html( ++no );
					
					alert( livereReply.initMessage.reactionB );
					
					break;
			}
		} );
		
	}
	
	this.openPage = function( re_code ) {
		var obj = livereReply.listManager.getObject( re_code );

		var domain = eval( obj.MEMBER_DOMAIN );
		if( domain && typeof(domain.openPage) == "function" ) {
			domain.openPage( obj );
		}
	}
	
	this.getArticle = function( params ) {
		
		var sort		= params['sort'];
		var page		= params['page'];
		var needClear	= params['needClear'];
		
		sort	= typeof(sort) == "string" ? sort : "new";
		page	= typeof(page) == "number" ? page : 1;
		
		livereReply.listManager.currentPage		= page;
		
		var param	= "apitype=list&sort=" + sort + "&page=" + page + "&pagesize=" + livereReply.moreDefine;
		
		var url = livereReply.url("LivereAPI" , param);
		
		jQuery.getJSON( url , function(data) {
			
			if( needClear ) {
				jQuery("#reply_list_wrapper").empty();
				livereReply.listManager.replys = Array();
				jQuery( ".sort_tab > li" ).removeClass();
				jQuery( "#" + sort ).parent("li").addClass("on");
			}
			
			var listData = livereReply.convertJSON( data , "FA" );
			
			if( listData == null ) {
				return;
			}
			
			jQuery("#moreBtn").remove();
			livereReply.listManager.drawList( listData );
			livereReply.listFirstInited = true;
		} );
		
	}

	this.addReply = function( re_code ) {
		this.listManager.drawReplyForm( re_code );
	}
	
	
	this.fire	= function( funName , params ) {
	
		var chainFunction	= livereReply.chainFunctionManager.getProcess( funName );
		var livereFunction	= null;
		
			switch( funName ) {
			case "addReply" :
				livereFunction = livereReply.listManager.addReply;
				break;
			
			case "sendAction" :
				livereFunction	= livereReply.sendAction;
				break;
			
			case "attachReply" :
				livereFunction	= livereReply.attachReply;
				break;
				
			case "getArticle" :
				livereFunction	= livereReply.getArticle;
				break;
			
			default :
				break;
		}
		
		if( livereFunction ) {
			if( chainFunction ) {
				return chainFunction( params , livereFunction );
			} else {
				return livereFunction( params );
			}
		}
		
	}
	
	// chainFunctionManager
	this.chainFunctionManager			= [];
	this.chainFunctionManager.getProcess = function( funName ) {
		for( var i = 0; i < livereReply.chainFunctionManager.length; i++ ) {
			var chain = livereReply.chainFunctionManager[i];
			if( chain.name == funName ) return chain.func;
		}
		return false;
	}
	
	this.listManager					= [];
	this.listManager.totalCount			= null;
	this.listManager.currentPage		= 1;
	this.listManager.listHeaderObject	= null;
	this.listManager.replys				= Array();
	
	this.listManager.totalCountControl = function (val) {
		this.totalCount = this.totalCount + val;
		jQuery("#totalCountDiv").html( this.totalCount );
	}
	
	this.listManager.drawList = function( listData ) {

		var listManager = this;
		
		jQuery( listData ).each( function( idx , obj ) {
			var reObject = listManager.getReplyHTML(obj);
			
			if( reObject ) {
				var param = {};
				param['replyObject'] = reObject;
				
				livereReply.fire("addReply" , param);
			}
		});
		
		var needMoreFlag = typeof(listData) == "object" && listData.length >= livereReply.moreDefine;
		
		livereReply.listManager.navigation( needMoreFlag );
	}
	
	
	this.listManager.navigation = function( needMore ) {
		
		var currentSort = jQuery( ".sort_tab > li" ).filter(".on").find("a").attr("id");
		var pageSize	= livereReply.moreDefine;
		var pageBlock	= livereReply.pageBlock;
		var currentPage = livereReply.listManager.currentPage;
		var totalRows	= livereReply.listManager.totalCount;

		if( livereReply.usePageNavigation ) {
	
			var totalPage	= totalRows % pageSize == 0 ? (totalRows / pageSize) : (totalRows / pageSize )+1;
				totalPage	= totalPage == 0 ? 1 : totalPage;
				totalPage	= Math.floor(totalPage);

			var startBlock	= 0;
			var endBlock	= 0;
			
			if( currentPage < livereReply.pageBlock + 1 ) {
				startBlock	= 1;
				endBlock	= livereReply.pageBlock;
			} else {
				startBlock	= currentPage % pageBlock == 0 ? 
								((currentPage / 10) - 1) * 10 + 1 
								: (Math.floor( currentPage / pageBlock ) * 10) + 1;
								
				endBlock	= startBlock + pageBlock - 1;
			}
			
			endBlock	= totalPage < endBlock ? totalPage : endBlock;
			var naviStr = "<div id='moreBtn'>";																				
			naviStr	+=	currentPage > pageBlock ? " <a class=\"livereReplyMoreBtn\" id=\"livereReplyPrev\" href=\"javascript:livereReply.fire('getArticle' , {'sort' : '" + currentSort + "' , 'page' : " + (startBlock - 1) + " , 'needClear' : " + true + " } );\">　</a> " : "";
			
			for(var i = startBlock; i <= endBlock; i++) {
				naviStr += currentPage == i ? " <b>" + i + "</b> " : " <a href=\"javascript:livereReply.fire('getArticle' , {'sort' : '" + currentSort + "' , 'page' : " + i + " , 'needClear' : " + true + " } );\">" + i + "</a>";
			}
			
			naviStr	+=	endBlock >= totalPage ? "" : " <a class=\"livereReplyMoreBtn\" id=\"livereReplyNext\" href=\"javascript:livereReply.fire('getArticle' , {'sort' : '" + currentSort + "' , 'page' : " + (endBlock + 1) + " , 'needClear' : " + true + " } );\">　</a> ";
			
			naviStr += "</div>";
			var naviStrObject = jQuery( naviStr );
			
			jQuery("#reply_list_wrapper").append( naviStrObject );
			
		} else if(needMore) {
		
			var moreBtnObject = jQuery("<a id='moreBtn'><span>More</span></a>");
			
			jQuery( moreBtnObject ).click( function() {
				var param = {};
				param['sort'] = currentSort;
				param['page'] = currentPage + 1;
				
				livereReply.fire( 'getArticle' , param )
			} );
			
			jQuery("#reply_list_wrapper").append( moreBtnObject );
		}
		
	}

	this.listManager.addReply = function ( params ) {
		
		var replyObject = null;
		var isNewReply	= null;
		
		if(params) {
			replyObject	= params['replyObject'];
			isNewReply	= params['isNewReply'];
		}
		
		var replyBody = replyObject.wrapper;
		//replyBody.css("display" , "none");
	
		if(replyObject.isSub) {
			var parentReply = livereReply.listManager.getObject( replyObject.RE_PARENT );
			parentReply.replyBody.append( replyBody );
		} else {
			if( livereReply.listManager.getNumChildren() == 0) {
				jQuery("#reply_list_wrapper").append( replyBody );
			} else if( isNewReply ) {
				jQuery("#reply_list_wrapper :first").before( replyBody );
			} else {
				jQuery("#reply_list_wrapper").append( replyBody );
			}
		}
		
		//replyBody.slideDown(400);
		
		return params;
	}
	
	this.listManager.getNumChildren = function() {
		return jQuery("#reply_list_wrapper").children().length;
	}
	
	this.listManager.getReplyHTML = function( re ) {
		if(!this.listHeaderObject) {
			var headerHTML = this.getListHeaderHTML();
			this.listHeaderObject = jQuery(headerHTML);
			
			this.listHeaderObject.ready( function() {
				livereReply.listManager.listHeaderObject.find(".sort_tab").find("a").click( function() {
				
					var params = {};
					params['sort']		= jQuery(this).attr("id");
					params['page']		= 1;
					params['needClear']	= true;
					
					livereReply.fire('getArticle' , params);
				} );
			} );
			
			jQuery("#platform_wrapper").after( this.listHeaderObject );
		}
		re.owner = livereReply.accountManager.isMember( re.MEMBER_SEQ );
		re.deleteAble = re.MEMBER_SEQ == "" || re.owner;
		re.isSecret = re.RE_CONTENT == "secretContent" && !re.owner;
		re.RE_CONTENT = re.isSecret ? livereReply.initMessage.secretContent : re.RE_CONTENT;
		re.MEMBER_DOMAIN	= re.MEMBER_DOMAIN == "" ? "guest" : re.MEMBER_DOMAIN.toLowerCase();
		re.USER_ICON		= re.USER_ICON == "" || typeof(re.USER_ICON) == "undefined" ? livereReply.guestIcon : re.USER_ICON;
		re.RE_NAME			= re.RE_NAME ? re.RE_NAME : re.MEMBER_NAME;
		
		re = re.RE_CODE != re.RE_PARENT ? livereReply.listManager.makeSubReplyHTML( re ) : livereReply.listManager.makeParentReplyHTML( re );
		this.replys.push( re );
		return re;
	}
	
	this.listManager.makeParentReplyHTML = function( re , isEmptyObject ) {
		
		var replyWrapper = "";
		replyWrapper += "<div class='articles_wrapper'>";
		replyWrapper += "</div>";

		var replyThumb = "";
		if( !isEmptyObject ) {
			replyThumb += "    <div class='thumbnail' onclick=\"javascript:livereReply.openPage('" + re.RE_CODE + "')\">";
			replyThumb += "    	<img src='" + re.USER_ICON + "'/>";
			replyThumb += "    </div>";
		}
		
		var replyBody = "";
		replyBody += "    <div class='articles_body_wrapper'> ";
		replyBody += "    <div class='articles_left_top'></div>";
		replyBody += "    <div class='articles_right_top'></div>";
		
		if( !isEmptyObject ) {
			replyBody += "        <dl class='article_content'>";
			replyBody += "			<dd class='article_writed_info'>";
			replyBody += "		        <span class='snsIcon' href='#'>";
			replyBody += "		        	<a href=\"javascript:livereReply.openPage('" + re.RE_CODE + "')\"><strong class='" + re.MEMBER_DOMAIN + "'>" + re.RE_NAME + "</strong></a>";
			replyBody += "                <span class=\"date\">" + re.RE_REGDATE1 + " " + re.RE_REGDATE2 + "</span>";
			replyBody += "		        </span>";
			replyBody += "	        </dd>";
			replyBody += "	        <dd class='article_function'>";
			
			if(re.deleteAble)
				replyBody += "                <a href=\"javascript:livereReply.deleteArticle('" + re.RE_CODE + "')\"><span class='delete_reply'></span></a>";			
			
			replyBody += "                <a href=\"javascript:livereReply.articleAction('" + re.RE_CODE + "' , 'police')\"><span class='flag_reply'></span></a>";
			replyBody += "                <a href=\"javascript:livereReply.articleAction('" + re.RE_CODE + "' , 'bad')\"><span class='dislike_reply'><strong class='sympathy_count'>" + re.RE_BAD + "</strong></span></a>";
			replyBody += "                <a href=\"javascript:livereReply.articleAction('" + re.RE_CODE + "' , 'good')\"><span class='like_reply'><strong class='recommend_count'>" + re.RE_AGREE + "</strong></span></a>";
			
			replyBody += "	        </dd>";
			replyBody += "	        <dd class='article_text'>";
			
			replyBody += "				<span class='re_content'>";
			
			
			if(re.RE_IMAGE != "") {
			
				var movieURL = re.RE_IMAGE;

				if( movieURL ) {
				
					if(movieURL.indexOf("youtu.be") != -1){
						movieURL = movieURL.replace("youtu.be", "www.youtube.com/embed");
						movieURL = movieURL.indexOf("&") != -1 ? movieURL.substring(0, movieURL.indexOf("&")) : movieURL;	
					} else if( movieURL.indexOf("/watch?v=") != -1) {
						movieURL = movieURL.replace("watch?v=", "embed/");
						movieURL = movieURL.indexOf("&") != -1 ? movieURL.substring(0, movieURL.indexOf("&")) : movieURL;
					}
					
					var videoThumb = movieURL.replace( "http://www.youtube.com/embed/", "" );			
					
					if(movieURL.indexOf("youtu") != -1) {
						replyBody += "       	    <div class='attach_image' onclick=\"javascript:livereReply.listManager.imageViewLayer('" + re.RE_CODE + "', '"+ movieURL +"')\" target='_blank'>";
						replyBody += "					<img src='http://i.ytimg.com/vi/"+ videoThumb +"/2.jpg'/>";
						replyBody += "					<iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"400\" height=\"330\" src='" + movieURL + "' frameborder=\"0\" allowFullScreen></iframe>";
						replyBody += "					<span>";
						replyBody += "						<strong>" + movieURL + "</strong>";
						replyBody += "						<a id='imageViewClose' class='overViewBtn' href=\"javascript:livereReply.listManager.imageViewLayerClose('" + re.RE_CODE + "', '"+ movieURL +"')\"></a>";
						replyBody += "						<a id='originImageView' class='overViewBtn' href='" + movieURL + "' target='_blank'></a>";
						replyBody += "					</span>";
						replyBody += "				</div>";
					} else {
						replyBody += "       	    <div class='attach_image' onclick=\"javascript:livereReply.listManager.imageViewLayer('" + re.RE_CODE + "', '" + re.RE_IMAGE + "')\" target='_blank'>";
						replyBody += "					<img src='" + movieURL + "'/>";
						replyBody += "					<span>";
						replyBody += "						<strong>" + re.RE_IMAGE + "</strong>";
						replyBody += "						<a id='imageViewClose' class='overViewBtn' href=\"javascript:livereReply.listManager.imageViewLayerClose('" + re.RE_CODE + "', '" + re.RE_IMAGE + "')\"></a>";
						replyBody += "						<a id='originImageView' class='overViewBtn' href='" + movieURL + "' target='_blank'></a>";
						replyBody += "					</span>";
						replyBody += "				</div>";
					}
				}
			}
			
			replyBody += 				re.RE_CONTENT + "</span>";
			replyBody += "			</dd>";
			replyBody += "        </dl>";
		}
		
		replyBody += "    <div class='articles_left_bottom'></div>";
		replyBody += "    <div class='articles_right_bottom'></div>";
		replyBody += "	  <div class='nodoctype_articles_wrapper_bottom'></div>";
		replyBody += "    </div>";

		var replyAddBtn = "";
		replyAddBtn += "        <a class='re_reply_button' href=\"javascript:livereReply.addReply('" + re.RE_CODE + "')\"></a>";

		re.wrapper		= jQuery( replyWrapper );
		re.replyThumb	= jQuery( replyThumb );
		
		//re.replyBody	= jQuery( livereReply.autoLink(replyBody) );
		re.replyBody	= jQuery( replyBody );
		
		re.replyAddBtn	= jQuery( replyAddBtn );
		
		re.replyBody.find(".re_content").append( re.replyAddBtn );
		re.wrapper.append ( re.replyThumb );
		re.wrapper.append ( re.replyBody );

		re.child = Array();

		re.isSub	= false;
		
		return re;
	}
	
	this.listManager.imageViewLayer = function( re_code, content ) {
		var obj = livereReply.listManager.getObject( re_code ).replyBody;
		
		if( content.indexOf("youtu") != -1 ) {
			obj.find(".attach_image > img").hide();	
			obj.find(".attach_image > img").removeClass("thumbNail");	
			obj.find(".attach_image > iframe").addClass("overView");
			obj.find(".attach_image > span").addClass("overViewNavi");
		} else {		
			obj.find(".attach_image > img").removeClass("thumbNail");	
			obj.find(".attach_image > img").addClass("overView");
			obj.find(".attach_image > span").addClass("overViewNavi");
		}		
	}
	
	this.listManager.imageViewLayerClose = function( re_code, content ) {		
		var obj = livereReply.listManager.getObject( re_code ).replyBody;
		
		if( content.indexOf("youtu") != -1 ) {	
			obj.find(".attach_image > img").show();	
			obj.find(".attach_image > iframe").removeClass("overView");
			obj.find(".attach_image > iframe").attr("src", content);
			obj.find(".attach_image > span").removeClass("overViewNavi");			
			obj.find(".attach_image > img").addClass("thumbNail");
		} else {		
			obj.find(".attach_image > img").removeClass("overView");
			obj.find(".attach_image > span").removeClass("overViewNavi");			
			obj.find(".attach_image > img").addClass("thumbNail");
		}			
	}
	
	this.listManager.makeSubReplyHTML = function( re ) { 
		var subReply = "";
			
		if(!livereReply.listManager.getObject( re.RE_PARENT )) {
			var emptyRe = Object();
			emptyRe.RE_CODE = re.RE_PARENT;
			emptyRe = livereReply.listManager.makeParentReplyHTML( emptyRe , true );
			livereReply.listManager.replys.push( emptyRe );
			
			var param = {};
			param['replyObject'] = emptyRe;
			
			livereReply.fire("addReply" , param);
		}
		
		subReply += "<div class='re_reply_article'>";
		//subReply += "<fieldset>";
		subReply += "    <dl class='article_content'>";
		subReply += "       <dd class=\"article_writed_info\">";
		subReply += "        	<span class=\"arrow\"></span>";
		subReply += "           <span class=\"snsIcon\" onclick=\"javascript:livereReply.openPage('" + re.RE_CODE + "')\"><strong class=\"" + re.MEMBER_DOMAIN + "\">" + re.RE_NAME + "</strong></span>";
		subReply += "            <span class=\"date\">" + re.RE_REGDATE1 + " " + re.RE_REGDATE2 + "</span>";	
		subReply += "       </dd>";
		
		subReply += "		<dd class=\"article_function\">";
		
		if(re.deleteAble)
			subReply += "            <a href=\"javascript:livereReply.deleteArticle('" + re.RE_CODE + "')\"><span class=\"delete_reply\"></span></a>";
		subReply += "            <a href=\"#\"><span class=\"flag_reply\"></span></a>";
		
		subReply += "    	</dd>";
                
		subReply += "        <dd class='article_text'>";
		subReply += "				<span class='re_content'>" + re.RE_CONTENT + "</span>";
		subReply += "		 </dd>";
		subReply += "    </dl>";
		//subReply += "</fieldset>";
		subReply += "</div>";

		re.isSub		= true;
		
		livereReply.listManager.getObject( re.RE_PARENT ).child.push( re );
		re.wrapper	= jQuery( livereReply.autoLink(subReply) );
		
		return re;
	}

	this.listManager.drawReplyForm = function( re_code ) {
		var obj = this.getObject( re_code );
		/*
		jQuery(".re_reply").slideUp(400 , function() {
			jQuery(this).remove();
		});
		*/
		jQuery(".re_reply").remove();

		if(obj.replyFormIsOpen) {
			obj.replyFormIsOpen = false;
			return;
		}

		var replyFormHTML = "";
		
		replyFormHTML += "<div class='re_reply'>";
		//replyFormHTML += "    <fieldset>";
		replyFormHTML += "    	<form name='re_reply_form' class='re_reply_form' onsubmit='return false;'>";
		replyFormHTML += "        	<textarea type='text' class='txt' id='replyText' ></textarea>"; 
		replyFormHTML += "        	<a onclick=\"javascript:livereReply.sendAction('" + re_code + "');\" class='btn'></a>";
		replyFormHTML += "    	</form>";
		//replyFormHTML += "    </fieldset>";
		replyFormHTML += "</div>";

		var replyFormObj = jQuery( replyFormHTML );
		
		//replyFormObj.css("display" , "none");
		
		obj.replyBody.find(".articles_right_bottom").after( replyFormObj );
		/*
		replyFormObj.slideDown('300' , function() {
			jQuery("#replyText").focus();
			
			var domain = obj.MEMBER_DOMAIN;
			
			if( domain == 'twitter' ) {
				jQuery("#replyText").val( "@" + obj.RE_NAME + " " );
				livereReply.changePrimary( domain , true );
			} else if( domain == 'me2day' ) {
				jQuery("#replyText").val( "\\" + obj.RE_NAME + "\\ " );
				livereReply.changePrimary( domain , true );
			}
			
			
			
		});
		*/		
		jQuery("#replyText").focus();
			
		var domain = obj.MEMBER_DOMAIN;
			
		if( domain == 'twitter' ) {
			jQuery("#replyText").val( "@" + obj.RE_NAME + " " );
			livereReply.changePrimary( domain , true );
		} else if( domain == 'me2day' ) {
			jQuery("#replyText").val( "\\" + obj.RE_NAME + "\\ " );
			livereReply.changePrimary( domain , true );
		}

		obj.replyFormIsOpen = true;
		
	}

	this.listManager.getObject = function( re_code ) {
		var returnObject = null;
		jQuery( this.replys ).each( function( idx , obj ) {
			if( obj.RE_CODE == re_code ) {
				returnObject = obj;
			}
		} );

		return returnObject;
	}

	this.listManager.getListHeaderHTML = function() {
		var listHeaderHTML = "";
		listHeaderHTML += "<div id='comment_sort'>";
		listHeaderHTML += "	<span>" + livereReply.initMessage.replyCount_txt + "<strong id='totalCountDiv' class='reply_count'>" + this.totalCount + "</strong>" + livereReply.initMessage.replyCount_txt2 + "</span>";
		listHeaderHTML += "	<ul class='sort_tab'>";
		listHeaderHTML += "		<li class='on'><a class='newReplyTab' id='new'></a></li>";
		listHeaderHTML += "		<li><a class='likeReplyTab' id='good'></a></li>";
		listHeaderHTML += "		<li><a class='dislikeReplyTab' id='bad'></a></li>";
		listHeaderHTML += "	</ul>";
		listHeaderHTML += "</div>";
		listHeaderHTML += "<div id='reply_list_wrapper'></div>";

		return listHeaderHTML;
	}

	this.listManager.deleteArticle = function ( re_code ) {

		var targetObject = livereReply.listManager.getObject( re_code );
		var deleteCount = targetObject.child ? (targetObject.child.length + 1) : 1;
		
		livereReply.listManager.totalCountControl( -deleteCount );
		/*
		targetObject.wrapper.slideUp(400 , function() {
			targetObject.wrapper.remove();
		} );
		*/
		targetObject.wrapper.remove();
	}

	this.deleteArticle = function( re_code ) {

		var targetObject = livereReply.listManager.getObject( re_code );
		
		if( targetObject.MEMBER_SEQ == "" && livereReply.guestManager ) {
			return livereReply.guestManager.deleteAction( targetObject );
		}
		
		if(!livereReply.accountManager.isMember( targetObject.MEMBER_SEQ )) {
			alert( livereReply.initMessage.deleteAuthFail );
			return;
		} else if(!confirm( livereReply.initMessage.deleteConfirm ))
			return;
		
		var url = livereReply.url("LivereDelete" , "re_code=" + re_code);
		jQuery.getScript( url , function() {
			switch( deleteResult ) {
				case "-1" :
					alert( livereReply.initMessage.needLogin );
					break;
				default :
					livereReply.listManager.deleteArticle( re_code );
					break;
			}

		} );
	}
	
	
	this.urlSet = {};
	this.urlSet.charset = typeof(document.charset) == "undefined" ? document.characterSet : document.charset;
	this.urlSet.array	= [
							{'apiname' : 'RenewMembership' , 'replace' : 'RenewMembership_kr'}, 
							{'apiname' : 'LivereAPI' , 'replace' : 'LivereAPI_kr'}, 
							{'apiname' : 'LivereInsert' , 'replace' : 'LivereInsert_kr'}, 
							{'apiname' : 'WriteGuest' , 'replace' : 'WriteGuest_kr'}
						];
	this.urlSet.getUrl = function( val ) {
		var flag = (livereReply.urlSet.charset.toUpperCase() == "UTF-8" || livereReply.urlSet.charset.toUpperCase() == "UTF8" || livereReply.urlSet.charset.toUpperCase() == "UTF");
		var returnAPIurl = null;
		
		jQuery( livereReply.urlSet.array ).each( function(idx , vv) {
			if( vv['apiname'] == val ) {
				returnAPIurl = vv['replace'];
				return false;
			}
		});
		
		if( returnAPIurl == null )
			return val;
		
		return flag ? val : returnAPIurl;
	}
	
	
	this.pluginLauncherInit = function() {
		var url = livereReply.url( "ver5/addon/plugin/loader.js" );
		jQuery.getScript( url );
	}

	this.init = function () {
	
		if( window.location.href.indexOf('ditto.gsshop.com') > -1 ) {
			livereReply.livereLoader();
			return;
		}
	
		jQuery(document).ready( function() {
			livereReply.livereListener();
		} );
		jQuery(window).scroll( function() {
			livereReply.livereListener();
		} );
	}
	
	this.livereListener = function() {
		if( !livereInited ) {
			var compareValue	= jQuery(window).scrollTop() + jQuery(window).height();
			var livereTop		= getCurrentPosition( document.getElementById( livereReply.targetDIV ) )['top'];
			
			if( livereTop != -1 && compareValue >= livereTop ) {
				livereReply.livereLoader();
			}
		}
	}
	
	var livereInited = false;
	this.listFirstInited = false;
	this.livereLoader = function() {

		if( livereInited ) return;

		livereInited = true;

		//if( livereReply.skin_id == "default" ) {
			var css = jQuery("<link href=\"http://www.livere.co.kr/ver5/css/default.css\" rel=\"stylesheet\" type=\"text/css\">");
			jQuery("head").append( css );
		//}
		/*
		jQuery.getScript( this.url("GetCssPath" , "skin_id=" + livereReply.skin_id) , function() {
			css = jQuery("<link href=\"" + cssPath + "\" rel=\"stylesheet\" type=\"text/css\">");
			jQuery("head").append( css );
		});
		*/
		var accounts = this.url( "LivereAccounts" , "s_id=" + livereReply.s_id );
		jQuery.getScript( accounts , function() {
			var html = livereReply.getFormHTML();
			jQuery("#" + livereReply.targetDIV).append( jQuery(html) );

			livereReply.pluginLauncherInit();
			//livereReply.secondStep();			
			setTimeout("livereReply.secondStep", 500);
		} );
	}
	
	this.secondStepInit = false;
	this.secondStep = function() {
	
		if( livereReply.secondStepInit ) return;
		livereReply.secondStepInit = true;
		livereReply.accountManager.setAccount();

		livereReply.renewMembership();
		
		if(livereReply.useGuest) {
			var url = livereReply.url( "ver5/addon/guest/guest.jsp?dummy=" + Math.random() );
			jQuery.getScript( url );
		}
		
		
		
		if( typeof(livereReply.listManager.totalCount) == 'object' ) {
			var param	= "apitype=count";
			var url = livereReply.url("LivereAPI" , param);
			jQuery.getJSON( url , function(data) {
				data = livereReply.convertJSON( data );
				livereReply.listManager.totalCount = parseInt( data.COUNT );
				if( livereReply.listManager.totalCount > 0 ) livereReply.fire('getArticle' , {});
			} );
		} else if( typeof(livereReply.listManager.totalCount) == 'number' && livereReply.listManager.totalCount > 0 ){
				livereReply.fire('getArticle' , {});
		}
		
		
		
		if(livereReply.shortConsumerKey) {
			var hv = jQuery("<input type='hidden' name='shortDomain' value='" + livereReply.shortConsumerKey + "' />");
			jQuery("#livereForm").append( hv );
		}
	}
	
	this.convertJSON = function( data , type ) {
		data = jQuery.trim(data);
		
		if( data != '' && data != '[]') {
		
			var arrExp = /^\[/g; var objExp = /^{/g; var brExp = /\n|\r|\r\n|\n\r/g;
			
			if( brExp.test( data ) ) {
				data = data.replace( brExp , livereReply.defaultNewline );
			}
			
			try { if( type ) { return type == "FA" ? eval(data) : eval("("+data+")"); }} catch( err ) {};
			
			if( arrExp.test(data) ) {
				return eval( data );
			} else if( objExp.test(data) ){
				return eval("("+data+")");
			}
			
			return eval("("+data+")");
		}
		
		return null;
	}
	
	this.setCustomShortURL = function( shortConsumerKey ) {
		this.shortConsumerKey = shortConsumerKey
	}
	
	
}

function getCurrentPosition(e) {   
	var l = 0;   
	var t = 0;   
	while (e.offsetParent) {   
		l += e.offsetLeft + (e.currentStyle ? VL_int(e.currentStyle.borderLeftWidth) : 0);   
		t += e.offsetTop + (e.currentStyle ? VL_int(e.currentStyle.borderTopWidth) : 0);   
		e = e.offsetParent;   
	}   
	l += e.offsetLeft + (e.currentStyle ? VL_int(e.currentStyle.borderLeftWidth) : 0);   
	t += e.offsetTop + (e.currentStyle ? VL_int(e.currentStyle.borderTopWidth) : 0);   
	return { 'left': l, 'top': t };   
} 

function VL_int(v) {   
	v = parseInt(v);   
	return isNaN(v) ? 0 : v;   
}